package com.zhxh.nzpos.login;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.zhxh.nzpos.R;

public class ImageAdapter  extends SimpleAdapter{
    private Context mContext;
    ImageView iView;
    private LayoutInflater mInflater;
    private String[] keys ;
    private int[] resIds ;
    private List<? extends Map<String, ?>> imageList;
    
    private int resourceId;
    
	public ImageAdapter(Context context, List<? extends Map<String, ?>> data,
			int resource, String[] from, int[] to) {
		
		super(context, data, resource, from, to);
		 mInflater = LayoutInflater.from(context);
		 imageList = data;
		 keys = from;
		 resIds = to;
		 resourceId = resource;
		// TODO Auto-generated constructor stub
	}
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

    	 convertView = mInflater.inflate(resourceId, null);
    	Map<String, ?> values =  imageList.get(position);
    	 
    	// for(int i = 0 ; i < imageList.size() ; i++) {
        	 for(int j = 0 ; j < resIds.length ; j++) {
         		View view = convertView.findViewById(resIds[j]);
         		if(view instanceof ImageView) {
         			 ImageView imageview = (ImageView) view;
         			 imageview.setImageResource((Integer)values.get(keys[j]));
         		}
         		else if(view instanceof TextView) {
         			TextView textview = (TextView) view;
         			textview.setText((String)values.get(keys[j]));
         		}
         		 
         	 }
    	// }
    	 

    	// ImageView imageview = (ImageView) convertView.findViewById(R.id.compose_grid_image);
    	// TextView textview = (TextView) convertView.findViewById(R.id.compose_grid_text);
    	// textview.setText(mTextIds[position]);

    	// imageview.setImageResource(R.drawable.);
    return convertView;
    }

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
